package com.znsb.msfq.adapter.comadapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.znsb.msfq.R;

import java.io.File;
import java.util.List;

/**
 * @name：
 * @author： 孙科技
 * @phone： 13308334117
 * @createTime： 2017/2/13
 * @modifyTime： 2017/2/13
 * @explain：
 */

public class MyAlbumAdapter extends RecyclerView.Adapter<MyAlbumAdapter.MyViewHoder> {
    private List<String> mImagePathList;
    public Context context;

    public MyAlbumAdapter(Context context, List<String> pathList) {
        this.context = context;
        this.mImagePathList = pathList;
    }

    public void notifyDataSetChanged(List<String> imagePathList) {
        this.mImagePathList = imagePathList;
        super.notifyDataSetChanged();
    }

    @Override
    public MyAlbumAdapter.MyViewHoder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        return new MyAlbumAdapter.MyViewHoder(inflater.inflate(R.layout.item_album_view, null));
    }

    @Override
    public void onBindViewHolder(MyViewHoder holder, final int position) {
        File file = new File(mImagePathList.get(position));
        Picasso.with(context).load(file)
                .placeholder(R.mipmap.addcomments_imges)
                .error(R.mipmap.addcomments_imges)
                .into(holder.mIvIcon);

    }

    @Override
    public int getItemCount() {
        return mImagePathList == null ? 0 : mImagePathList.size();
    }

    public static class MyViewHoder extends RecyclerView.ViewHolder {
        ImageView mIvIcon;

        public MyViewHoder(View itemView) {
            super(itemView);
            mIvIcon = (ImageView) itemView.findViewById(R.id.image);
        }
    }

}
